package com.gxc.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author GongXincheng
 * @since 2019-10-13 00:55
 */
@Component
public class MockQueue {

    private final Logger log = LoggerFactory.getLogger(getClass());

    /**
     * 下单
     */
    private String placeOrder;

    /**
     * 订单完成
     */
    private String completeOrder;


    public String getPlaceOrder() {
        return placeOrder;
    }

    /**
     * 模拟下单请求.
     */
    public void setPlaceOrder(String placeOrder) throws InterruptedException {
        new Thread(() -> {
            log.info("接到下单请求，{}", placeOrder);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            this.completeOrder = placeOrder;
            log.info("下单请求处理完成，{}", placeOrder);
        }).start();
    }

    public String getCompleteOrder() {
        return completeOrder;
    }

    public void setCompleteOrder(String completeOrder) {
        this.completeOrder = completeOrder;
    }
}
